<%-- 
    Document   : index
    Created on : 2013-4-23, 20:28:19
    Author     : Administrator
--%>
<%String path = request.getContextPath();%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <c:import url="/resource/include/header.jsp" />
        <title>这是一个测试例子</title>
    </head>
    <body>
        <div id="header">
            <c:import url="/resource/templates/default/header.html" charEncoding="UTF-8"/>
        </div>
        <div id="main">
            <form method="get" id="frm" name="frm" target="_self">
                <table border ="1" width="600" style="margin: 20px 0px 0px 20px">
                    <tr>
                        <td colspan="3" align="left">
                            <input type="text" id="query" name="query" />  <a href="javascript:doQueryStu();">检索</a>
                            <a href="javascript:doAddStuWin()">新增</a>
                            <a href="javascript:doDelStu()">删除</a>
                            <a href="javascript:modyfiyStu()">修改</a>
                        </td>
                    </tr>
                    <tr style="background-color: antiquewhite">
                        <td>序号</td> <td>学生姓名</td><td>班级</td>
                    </tr>
                    <c:forEach items="${stus}" var="stu">
                        <tr>
                            <td><input type="checkbox" name="sid" value="${stu.id}"> ${stu.id}</td>
                            <td>${stu.name}</td>
                            <td>${stu.s_class.className}</td>
                        </tr>
                    </c:forEach>   
                </table>
                <script>
                    function doAddStuWin(){
                        win.dialog({         id:"adddilog",
                            title:"新增学生",
                            href:"<%=path%>/app/index/goAddStu/",
                            width:300,
                            height:200
                        });
                    }
                    function modyfiyStu(){
                        var chk = $(":checkbox:checked");
                        if(chk.length==0){
                            win.alert("提示", "至少选择一条");return;  
                        }
                        if(chk.length>1){
                            win.alert("提示", "只能选择一条");return;
                        }
                        var id = chk[0].value;
                        win.dialog({
                            id:"modfiyStu",
                            title :"修改",
                            href:"<%=path%>/app/index/goModfiyStu/"+id,
                            width:300,
                            height:200
                        });
                
                    }
                    var id = "";
                    function delStu(){
                        var chk = $(":checkbox:checked");
                        if(chk.length==0){
                            win.alert("提示", "至少选择一条");return;  
                        }
                        if(chk.length>1){
                            win.alert("提示", "只能选择一条");return;
                        }
                        win.confirm("提示", "确定要删除吗", doDelStu);
                    }
                    function doDelStu(){
                        var chk = $(":checkbox:checked");
                        id = chk[0].value;
                        $.ajax({
                            type: "get",
                            url: "<%=path%>/app/index/delStu/"+id,
                            success: function(msg){
                                if(msg == 1){
                                    win.messageBox("恭喜", "删除成功", function(){location.reload()});
                                }else{
                                    win.messageBox("错误","删除失败");
                                }
                            }
                        });
                    }
                    function doQueryStu(){
                        var name = $("#query").val();
                        if(name==""){
                            win.alert("提示", "查询条件不能空");return ;
                        }
                        document.forms[0].action = "<%=path%>"+"/app/index/findStu/"+name;
                        document.forms[0].submit();
                    }

                </script>
            </form>
        </div> 
        <div id="footer">
            <c:import url="/resource/templates/default/footer.html" charEncoding="UTF-8"/>
        </div>             
    </body>
</html>
